<extend name="common:commonNewerTemplate" />
<block name="main_content">
<div id="content">
	<div id="content-header">
		<div id="breadcrumb">
			<a class="tip-bottom" href="index.html"
				data-original-title="Go to Home"><i class="icon-home"></i> 首页</a>
			<a href="#">订单管理</a> <a class="current" href="#">订单信息</a>
		</div>
	</div>
	<div class="container-fluid">
		<div class="row-fluid">
			<div class="span12">
				<div class="widget-box">
					<div class="widget-title">
						<span class="icon"> <i class="icon-info-sign"></i>
						</span>
						<h5>搜索条件</h5>
					</div>
					<div class="widget-content nopadding">
						<form novalidate="novalidate" id="basic_validate"
							name="basic_validate" action="#" method="post"
							class="form-horizontal">
							<input type="hidden" value="2" name="dealer_channel">
							<div class="control-group">
								<label class="control-label">订单编号</label>
								<div class="controls">
									<input type="text" id="order_id" name="order_id">
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">经销商编号</label>
								<div class="controls">
									<input type="text" id="dealer_id" name="dealer_id">
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">经销商姓名</label>
								<div class="controls">
									<input type="text" id="dealer_name" name="dealer_name">
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">订单状态：</label>
								<div class="controls">
								<select id="order_status" name="order_status" style="width:220px;" >
									<option value="">--请选择--</option>
									<option value="10">已提交</option>
									<option value="11">已审核</option>
									<option value="12">订单处理中</option>
									<option value="14">销售管理部审核</option>
									<option value="15">财务审核</option>
									<option value="21">待支付</option>
									<option value="22">已支付</option>
									<option value="23">已上传付款凭证</option>
									<option value="25">物流处理中</option>
									<option value="26">物流异常</option>
									<option value="31">已全部发货</option>
									<option value="33">部分发货</option>
									<option value="32">已签收</option>
									<option value="35">已完成</option>
									<option value="41">退货中</option>
									<option value="42">退货完成</option>	
									<option value="43">换货中</option>	
									<option value="44">换货完成</option>	
									<option value="51">用户取消</option>	
									<option value="52">客服取消</option>	
									<option value="53">系统自动取消</option>
								</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">支付状态：</label>
								<div class="controls">
								<select id="payment_status" name="payment_status" style="width:220px;" >
									<option value="">--请选择--</option>
									<option value="0">未支付</option>
									<option value="1">已支付</option>
									<option value="2">部分支付</option>
									<option value="3">已退款</option>
									<option value="4">付款中</option>
								</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">经销商类型：</label>
								<div class="controls">
								<select id="dealer_type" name="dealer_type" style="width:220px;" >
									<option value="">--请选择--</option>
									<option value="1">一般纳税人</option>
									<option value="2">个体工商户</option>
								</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">订单日期：</label>
								<div class="controls">
									<!-- <input id="start_date" class="laydate-icon" onclick="laydate()" readonly>-
									<input id="end_date" class="laydate-icon" onclick="laydate()" readonly> -->
									<input id="start_date" name="start_date" style="background-color: #fff;border: 1px solid #ccc;box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;width:217px;color:#555;transition: border 0.2s linear 0s, box-shadow 0.2s linear 0s;" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">-
									<input id="end_date" name="end_date" style="background-color: #fff;border: 1px solid #ccc;box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;width:217px;color:#555;transition: border 0.2s linear 0s, box-shadow 0.2s linear 0s;" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
								</div>
							</div>
							<div class="form-actions">
								<input id="btn_search" type="button" class="btn btn-success" value="搜索">
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	
	<div class="row-fluid">
      <div class="span12">
        <div class="widget-box">
          <div class="widget-title"> <span class="icon"> <i class="icon-th"></i> </span>
            <h5>搜索结果</h5>
              <span style="float:right;margin:3px;">
				<a href="#" class="btn btn-primary" id="exportXls">导出订单列表xls</a>
			</span>
          </div>
          <div class="widget-content nopadding">
            <table id="search_result"  class="table table-bordered table-striped">
              <thead>
					<tr>
					  <th>订单编号</th>
					  <th>经销商编号</th>
					  <th>经销商姓名</th>
					  <th>经销商类型</th>
	                  <th>订单状态</th>
	                 <!--  <th>订单类型</th>
	                  <th>支付类型</th>
	                  <th>支付方式</th> -->
	                  <th>订单时间</th>
	                  <th>支付状态</th>
	                  <th>商品总金额</th>
	                  <th>订单优惠金额</th>
	                  <th>订单总金额</th>
	                  <th>操作</th>
					</tr>
				</thead>
              <tbody>
              </tbody>
            </table>
          </div>
      </div>
     </div>
		 <div id="paging" class="fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix">
        	<div class="dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi ui-buttonset-multi paging_full_numbers" id="DataTables_Table_0_paginate">
        		<a page_index="1" class="first ui-corner-tl ui-corner-bl fg-button ui-button ui-state-default" tabindex="0" id="DataTables_Table_0_first">首页</a>
        		<a class="previous fg-button ui-button ui-state-default" tabindex="0" id="DataTables_Table_0_previous">上页</a>
        		<span>共<span id="total_count">0</span>条 <span id="curr_page_index">0</span>/<span id="total_page">0</span></span>
       			<a class="next fg-button ui-button ui-state-default" tabindex="0" id="DataTables_Table_0_next">下页</a>
       			<a class="last ui-corner-tr ui-corner-br fg-button ui-button ui-state-default" tabindex="0" id="DataTables_Table_0_last">末页</a>
       			<span>
        			<span><input type="text" style="width:20px;" class="ui-state-default" id="jump_num"></span>
        			<a class="fg-button ui-button ui-state-default" id="DataTables_Table_jump" tabindex="0">跳转</a>
       			</span>
       		</div>
    	</div>
    </div>
  </div>

</div>
</block>

<block name="js_content">
<script src="../../../Public/js/laydate/laydate.js"></script>
<script >
	OrderInfoListPage = {
			'BindEvent': function(){
                $('#exportXls').bind('click', function(){
                    //var order_status	= $('#order_status').val();
                    //var payment_status	= $('#payment_status').val();
                    /* if(order_status != 22 || payment_status != 1){
                        alert('订单状态需选“已支付”，支付状态需选“已支付”');
                        return;
                    } */
                    
                	var startdate	= $('#start_date').val();
    				var enddate	= $('#end_date').val();
    				
    					if(startdate ==""){
    						alert("开始日期不能为空！！！");
    						return ;
    					}
    				   			
    					if(enddate ==""){
    						alert("结束日期不能为空！！！");
    						return ;
    					}
    				
    					var startdates = startdate.split('-');
    					var enddates = enddate.split('-');

    					startdate = startdates[1] + '/' + startdates[2].split(" ")[0] + '/' + startdates[0]+" "+startdates[2].split(" ")[1] ;
    							
    					enddate = enddates[1] + '/' + enddates[2].split(" ")[0] + '/' + enddates[0]+" " +enddates[2].split(" ")[1];
                        //alert(startdates);
    					//alert(startdate);
    					
    					// MM/dd/yyyy HH:mm:ss
    					// alert(Date.parse(startdate));
    					 //alert(Date.parse(enddate));
    					 
    					// var b = (Date.parse(enddate) - Date.parse(startdate)) / ( 3600 * 1000);
    					// alert(b);
    					 var a = Date.parse(enddate) - Date.parse(startdate) ;
    					
    					 if(a < 0){
    							alert("结束时间不能早于开始时间,请检查!");
    							return ;
    						}else{
    							 a = a/(24*3600*1000.0);
    							if(a >60){
    								
    								alert("只能导出2个月内的出货单!请检查日期!");
    								return ;
    							}
    							
    						}
    					
    					
                    var export_url = '/VRDealer/shipOrderExcel?' + $("#basic_validate").serialize();
                    window.open(export_url);
                });
				$('#btn_search').bind('click', function(){
					var page_index = 1;
					OrderInfoListPage.Search(page_index);
				});
				$('#DataTables_Table_jump').bind('click',function(){
					var page_index =  $('#jump_num').val();
					if(!isNaN(page_index)){
						OrderInfoListPage.Search(page_index);
					}else{
					   alert("跳转必须页必须为数字");
					}
				});
				$(".first,.previous,.last,.next").bind('click', function(){
					if($(this).hasClass('ui-state-disabled')){
						return false;
					}
					var page_index = $(this).attr('page_index');
					if(page_index == undefined){
						page_index = 1;
					}
					OrderInfoListPage.Search(page_index);
				});
			},
			'Search': function(page_index){
				var order_id		= $('#order_id').val();
				var dealer_id		= $('#dealer_id').val();
				var dealer_name		= $('#dealer_name').val();
				var order_status	= $('#order_status').val();
				var payment_status	= $('#payment_status').val();
				var dealer_type	= $('#dealer_type').val();
				var start_date	= $('#start_date').val();
				var end_date	= $('#end_date').val();
				if(end_date !=""){
					if(start_date ==""){
						alert("开始日期不能为空！！！");
						return ;
					}
				}
				if(start_date !=""){
					if(end_date ==""){
						alert("结束日期不能为空！！！");
						return ;
					}
				}
				var page_size		= 10;
				var dealer_channel =2;
				var result = OrderInfoListService.SearchOrderInfoList(order_id,dealer_id,dealer_name,order_status,payment_status,dealer_type,start_date,end_date,dealer_channel,page_index, page_size);
				if(result.IsSuccess == 0){
					alert(result.ErrorMsg);
					return;
				}else{
					OrderInfoListPage.FillTable(result.Result.lst_order_info_en, page_index);
					OrderInfoListPage.SetPageIndex(result.Result.total_page, result.Result.total_count, page_index);
				}
			},
			'FillTable': function(lst_order_info_en, page_index){
				var html_array = new Array();
				if(lst_order_info_en.length > 0){
					for(var index in lst_order_info_en){
						var order_info_en = lst_order_info_en[index];
						html_array.push('<tr class="odd gradeX">');
						html_array.push('<td>' + order_info_en.order_id + '</td>');
						html_array.push('<td>' + order_info_en.dealer_id + '</td>');
						html_array.push('<td>' + order_info_en.dealer_name + '</td>');
						html_array.push('<td>' + order_info_en.dealer_type_text + '</td>');
						html_array.push('<td>' + order_info_en.order_status_text + '</td>');
					/* 	html_array.push('<td>' + order_info_en.order_type_text + '</td>');
						html_array.push('<td>' + order_info_en.payment_type_text + '</td>');
						html_array.push('<td>' + order_info_en.payment_method_text + '</td>'); */
						html_array.push('<td>' + order_info_en.order_date + '</td>');
						html_array.push('<td>' + order_info_en.payment_status_text + '</td>');
						html_array.push('<td>' + order_info_en.goods_amount + '</td>');
						html_array.push('<td>' + order_info_en.discount_fee + '</td>');
						html_array.push('<td>' + order_info_en.order_amount + '</td>');
						html_array.push('<td><div style="text-align:center;"><a style="color:blue;" href="/Order/orderdetail?order_id=' + order_info_en.order_id + '">订单详情</a> <a style="color:blue;" href="/VRDealer/detail?order_id=' + order_info_en.order_id + '">经销商订单详情</a></div></td>');
						html_array.push('</tr>');
					}
				}
				else{
					html_array.push('<td style="text-align:center" colspan="9">没查到数据</td>');
				}
				
				var html = html_array.join('\r\n');
				$('#search_result tbody').html('');
				$('#search_result tbody').html(html);
				
				$('#search_result').attr('page_index', page_index);;
			},
			'SetPageIndex': function(total_page, total_count, page_index){
				$('#total_count').text(total_count);
				$('#total_page').text(total_page);
				$('#curr_page_index').text(page_index);
				page_index = parseInt(page_index);
				
				if(page_index == 1){
					$('#paging .first').addClass('ui-state-disabled');
					$('#paging .previous').addClass('ui-state-disabled');
					$('#paging .first').attr('page_index', 1);
					$('#paging .previous').attr('page_index', 1);
				}
				else{
					$('#paging .first').removeClass('ui-state-disabled');
					$('#paging .previous').removeClass('ui-state-disabled');
					$('#paging .first').attr('page_index', 1);
					$('#paging .previous').attr('page_index', page_index - 1);
				}
		
				if(total_page == page_index){
					$('#paging .last').addClass('ui-state-disabled');
					$('#paging .next').addClass('ui-state-disabled');
					$('#paging .last').attr('page_index', total_page);
					$('#paging .next').attr('page_index', total_page);
				}
				else{
					$('#paging .last').removeClass('ui-state-disabled');
					$('#paging .next').removeClass('ui-state-disabled');
					$('#paging .last').attr('page_index', total_page);
					$('#paging .next').attr('page_index', page_index + 1);
				}
		 },
	};
	$(document).ready(function(){
		OrderInfoListPage.BindEvent();
	});
</script>
</block>